﻿using static CyberU;
using static CyberU.UI;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
using System;

public class AlbumItem : ClickTextSelectItem
{
    public ClickText item;
    public AudioSource audioSource;

    public string path;
    public bool loop = false;
    public int index;

    void Start()
    {
        // gameObject.SetActive(true);
        // StartCoroutine(AppendAudioSource(filePath, parent: gameObject, loop: loop, onAudioSourceReady: OnAudioSourceReady, playOnAwake: playOnAwake));
        // gameObject.SetActive(false);
    }

    public static AlbumItem CreateAlbumItem(MusicPlayer parent ,int index,string path,bool playOnAwake=false,bool loop=false)
    {
        GameObject albumItemPrefab = GetPrefab("AlbumItem");
        // Delog($"{Used(parent.selector)}");
        GameObject instance = Instantiate(albumItemPrefab, parent.songsSelector.transform);
        AlbumItem albumItem = instance.GetComponent<AlbumItem>();
        albumItem.index = index;
        albumItem.item = instance.AddComponent<ClickText>();
        
        albumItem.path = path;
        albumItem.loop = loop;

        // AddRect(component: albumItem, color: Color.green);
        return albumItem;
    }
}